package com.itheima.config;

import com.itheima.pojo.Apple;
import com.itheima.pojo.User;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <dl>
 * <dd>描述: ~节点业务逻辑实现</dd>
 * <dd>创建时间：  11:19 2020/8/17</dd>
 * <dd>创建人： zz</dd>
 * <dt>版本历史: </dt>
 * <pre>
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2020/8/17      guodong       1.0        1.0 Version
 * </pre>
 * </dl>
 */
@Configuration //声明是一个配置类
public class UserConfig {
    @Bean
    public Apple apple(){
        return new Apple();
    }
    /*
        注入spring容器
            --》beanfactory 兵工厂
        原生注解：
            @Conditional(MyCondition.class)
        派生注解/衍生注解：
           @ConditionalOnBean(Apple.class):
                如果当前容器中存在apple bean 那么返回true
           @ConditionalOnMissingBean(Apple.class)
                如果当前容器中存在apple bean 那么返回false
           @ConditionalOnProperty(name = "itheima", havingValue = "28")
                从配置文件中查找key=itheima val = 28的配置，如果存在则返回true
     */
    //@Conditional(MyCondition.class)
    //@ConditionalOnBean(Apple.class)
    //@ConditionalOnMissingBean(Apple.class)
    @ConditionalOnProperty(name = "itheima", havingValue = "28")
    @Bean
    public User user(){
        User user = new User();
        user.setAge(16);
        user.setName("金莲");
        return user;
    }
}
